﻿using EventHandlerDemo.Domain.Orders;
using MediatR;

namespace EventHandlerDemo.Application.Orders;

public interface IOrderAppService
{
    Task<int> CreateaAsync();
}

public class OrderAppService : IOrderAppService
{
    private readonly IMediator _mediator;

    public OrderAppService(IMediator mediator)
    {
        _mediator = mediator;
    }

    public async Task<int> CreateaAsync()
    {
        var order = new Order()
        {
            Name = Guid.NewGuid().ToString(),
        };
        await _mediator.Publish(order.DomainEvents.First());
        return 0;
    }
}